package fr.cephb.util;

import java.io.IOException;
import java.io.InputStream;

import fr.cephb.io.IOUtils;

/** simple utility for the java resources */
public class ResourceUtils {
protected ResourceUtils() {}

/** return the content of the given resource as a String */
static public String getContent(Class<?> c,String rsrcName)
	{
	return getContent(c,rsrcName,null);
	}
/** return the content of the given resource as a String  or defaultValue if the resource
 * was not found */
static public String getContent(Class<?> c,String rsrcName,String defaultValue)
	{
	InputStream in=c.getResourceAsStream(rsrcName);
	if(in==null) return defaultValue;
	try{
		return IOUtils.copyToString(in);
		}
	catch(IOException err)
		{
		throw new RuntimeException("Probeme with "+rsrcName+" "+err.getMessage(),err);
		}
	}
}
